package commonDataStructures;

import java.util.ArrayList;
import java.util.Collections;

public class PSortedCollection<E extends Comparable<E>> implements PrimitiveCollection<E>{
	
	ArrayList<E> _arr;
	
	public PSortedCollection(){
		_arr = new ArrayList<E>();
	}
	@Override
	public void init() {
		_arr.clear();
	}

	@Override
	public void insert(E e) {
		_arr.add(e);
		Collections.sort(_arr);
	}

	@Override
	public boolean isEmpty() {
		return _arr.isEmpty();
	}

	@Override
	public E remove() {
		return _arr.remove(0);
	}

	@Override
	public int size() {
		return _arr.size();
	}
	
	public static void main(String[] args){
		PSortedCollection<Integer> a = new PSortedCollection<Integer>();
		a.insert(5);
		a.insert(4);
		a.insert(9);
		while (!a.isEmpty()){
			System.out.println(a.remove());
		}
	}

}
